#include "sAck.h"

#include <stdlib.h>
#include <sstream>
#include <stdio.h>

#include <Poco/DOM/Document.h>
#include <Poco/DOM/NodeIterator.h>
#include "misc/Debug.h"
#include "server/net/NetworkControl.h"
/*********************************************************/
void sAck::execute()
{
	NetworkControl& nc = NetworkControl::Instance();
	
	nc.mutex->lock();
	ACKMAP_::iterator it = nc.ackmap.find(addr.toString());
	if ( it != nc.ackmap.end() ) {
		std::map<unsigned long, std::string>::iterator it2 = it->second.find(id);
		if ( it2 != it->second.end() ) {
			it->second.erase(it2);

			if ( it->second.size() == 0 ) {
				nc.ackmap.erase(it);
			}
			nc.mutex->unlock();
			return;
		}
	}
	nc.mutex->unlock();
}
/*********************************************************/
std::string sAck::serialize() const
{
	std::ostringstream		xml;

	// Build the xml string for this job
	xml << "<GS id='" << id << "'>";
	xml << "<ACK></ACK>";
	xml << "</GS>";

	return( xml.str() );
}
/*********************************************************/
void sAck::deserialize(Poco::XML::NodeIterator& it)
{
	// this message doesn't carry any particular type of data
}
/*********************************************************/
void sAck::setData(const std::string& d)
{
	data = d;
}
/*********************************************************/
void sAck::setOrder(const unsigned int& p)
{
	order = p;
}
/*********************************************************/
std::string sAck::getData() const
{
	return data;
}
/*********************************************************/
unsigned int sAck::getOrder() const
{
	return order;
}
/*********************************************************/
